//
//  UIButton+EX.swift
//  sinaWeibo
//
//  Created by 董艳武 on 16/2/20.
//  Copyright © 2016年 董艳武. All rights reserved.
//

import UIKit
extension UIButton {
    convenience init (img:String,bgImg:String?,title:String,titleFontSize:CGFloat,titleColor:UIColor) {
        self.init()
        setImage(UIImage(named: img), forState: .Normal)
        if let useless:String = bgImg {
        setBackgroundImage(UIImage(named: useless), forState: .Normal)
        }
        setTitle(title, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(titleFontSize)
        setTitleColor(titleColor, forState: .Normal)
        sizeToFit()
    }
    
    convenience init (img:String?,bgImg:String?) {
        self.init()
        if img != nil {
            self.setImage(UIImage(named: img!), forState: .Normal)
            self.setImage(UIImage(named: img! + "_highlighted"), forState: .Highlighted)
        }
        if bgImg != nil {
            self.setBackgroundImage(UIImage(named: bgImg!), forState: .Normal)
            self.setBackgroundImage(UIImage(named: bgImg! + "_highlighted"), forState: .Highlighted)
        }
        sizeToFit()
    }
}
